#ifndef RELATIONPORTLIST_H
#define RELATIONPORTLIST_H

#include <QObject>
#include <QList>
#include <QMutex>

#include "uml/relations/umlrelation.h"
#include "uml/relations/ports/relationport.h"

class UmlRelationalItem;

class RelationPortList : public QObject
{
    Q_OBJECT
public:
    enum SortMode {
        NORTH_SOUTH_SORTING,
        WEST_EAST_SORTING
    };

    RelationPortList();
    ~RelationPortList();

    QList<UmlRelation*> relations();
    QList<RelationPort*> relationPorts();

    void appendRelation(UmlRelation *relation, RelationPort *port);
    void removeRelation(UmlRelation *relation);

    RelationPort* portOfRelation(UmlRelation *relation);
    UmlRelation* relationOfPort(RelationPort *port);

    int countRelations();
    int countPorts();
    int countRelationsWithPort(RelationPort *port);

    bool containsRelation(UmlRelation *relation);

    void setSortMode(RelationPortList::SortMode sortMode, UmlRelationalItem *relationalItem);

protected:
    QList<UmlRelation*> _relationList;

    QList<RelationPort*> _portList;

    QMap<UmlRelation*, RelationPort*> _relationToPortDictionary;

    QMutex _mutex;

    SortMode _sortMode;

    UmlRelationalItem  *_relationalItem;

    int insertPosition(UmlRelation *relation);

signals:
    void dataHasChanged();

};

#endif // RELATIONPORTLIST_H
